package com.example.zookeeper.config;

import org.apache.zookeeper.ZooKeeper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;

@Configuration
public class ZookeeperConfig
{

    @Bean
    public ZooKeeper zooKeeper() throws IOException, InterruptedException
    {
        final CountDownLatch latch = new CountDownLatch(1);
        ZooKeeper zooKeeper = new ZooKeeper("192.168.3.91:2181", 10 * 1000, watchedEvent ->
        {
            System.out.println("zookeeper 连接成功");
            latch.countDown();
        });
        latch.await();
        return zooKeeper;
    }
}
